<!-- newsfeed.php -->
<?php
$conn = new mysqli("localhost", "root", "", "db");
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT p.*, u.name FROM posts p JOIN users u ON p.user_id = u.id WHERE p.is_public = 1 ORDER BY p.created_at DESC";
$result = $conn->query($sql);

$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态流</title>
</head>
<body>
    <h3>动态流</h3>
    <?php if ($result->num_rows > 0): ?>
        <ul>
            <?php while ($post = $result->fetch_assoc()): ?>
                <li>
                    <p><?php echo htmlspecialchars($post['name']); ?>: <?php echo htmlspecialchars($post['content']); ?></p>
                    <?php if ($post['image']): ?>
                        <img src="uploads/<?php echo htmlspecialchars($post['image']); ?>" alt="动态图片">
                    <?php endif; ?>
                </li>
            <?php endwhile; ?>
        </ul>
    <?php else: ?>
        <p>暂无动态</p>
    <?php endif; ?>
</body>
</html>